import * as Cesium from "cesium";
function fluidPolylinetrend(color, duration, d, imgUrl) {
    this._definitionChanged = new Cesium.Event();
    this._color = undefined;
    this._image = undefined;
    this._colorSubscription = undefined;
    this.color = color;
    this.image = imgUrl;
    this.duration = duration || 3000;
    this._time = new Date().getTime();
    this._d = d;
    this.isTranslucent = function () {
        return true;
    };
}
Object.defineProperties(fluidPolylinetrend.prototype, {
    isConstant: {
        get: function () {
            return false;
        },
    },
    definitionChanged: {
        get: function () {
            return this._definitionChanged;
        },
    },
    color: Cesium.createPropertyDescriptor("color"),
    image: Cesium.createPropertyDescriptor("image"),
});
fluidPolylinetrend.prototype.getType = function (time) {
    return "PolylineTrailLink";
};
fluidPolylinetrend.prototype.getValue = function (time, result) {
    if (!Cesium.defined(result)) {
        result = {};
    }
    result.color = Cesium.Property.getValueOrClonedDefault(
        this._color,
        time,
        Cesium.Color.WHITE,
        result.color
    );
    // result.image = Cesium.Material.PolylineTrailLinkImage;
    result.image = Cesium.Property.getValueOrUndefined(this._image, time);
    result.time =
        (((new Date().getTime() - this._time) % this.duration) /
            this.duration) *
        this._d;
    return result;
};
fluidPolylinetrend.prototype.equals = function (other) {
    return (
        this === other ||
        (other instanceof fluidPolylinetrend &&
            Property.equals(this._color, other._color)&&
            Cesium.Property.equals(this._image, other._image))
    );
};
Object.fluidPolylinetrend = fluidPolylinetrend;
Cesium.Material.PolylineTrailLinkType = "PolylineTrailLink";
// Cesium.Material.PolylineTrailLinkImage = colors1;
Cesium.Material.PolylineTrailLinkSource =
    " czm_material czm_getMaterial(czm_materialInput materialInput)\n\
        {\n\
            czm_material material = czm_getDefaultMaterial(materialInput);\n\
            vec2 st = materialInput.st;\n\
            vec4 colorImage = texture(image, vec2(fract(st.s - time), st.t));\n\
            material.alpha = colorImage.a * color.a;\n\
            material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
            return material;\n\
        }";
Cesium.Material._materialCache.addMaterial(
    Cesium.Material.PolylineTrailLinkType,
    {
        fabric: {
            type: Cesium.Material.PolylineTrailLinkType,
            uniforms: {
                color: new Cesium.Color(0.0, 0.0, 1.0, 0.5),
                // image: Cesium.Material.PolylineTrailLinkImage,
                image: Cesium.Material.DefaultImageId,
                time: -20,
            },
            source: Cesium.Material.PolylineTrailLinkSource,
        },
        translucent: function (material) {
            return true;
        },
    }
);

function liudongxian(viewer, color, imgUrl, duration, positions) {
    viewer.entities.add({
        name: 'PolylineTrail',
        polyline: {
            positions: Cesium.Cartesian3.fromDegreesArray(positions),
             width: 2,
             material: new Object.fluidPolylinetrend(color, duration,1,imgUrl)
         }
    });
}
export default { liudongxian };
